package com.incar.chuxing.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.incar.chuxing.R;
import com.incar.chuxing.api.ApiStore;
import com.incar.chuxing.api.UrlConstant;
import com.incar.chuxing.base.BaseActivity;
import com.incar.chuxing.bean.LogoffBean;
import com.incar.chuxing.bean.UserCarInforBean;
import com.incar.chuxing.utils.AppManager;
import com.incar.chuxing.utils.MyApplication;
import com.incar.chuxing.utils.SharedPreferencesKey;
import com.incar.chuxing.utils.SharedPreferencesUtils;
import com.incar.chuxing.utils.Toast.ToastCompat;
import com.incar.chuxing.utils.VerControlUtils;
import com.umeng.message.UTrack;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class CarVerifyInfoActivity extends BaseActivity {

    @BindView(R.id.title_name)
    TextView titleName;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_cartype)
    TextView tvCartype;
    @BindView(R.id.tv_starttime)
    TextView tvStarttime;
    @BindView(R.id.tv_endtime)
    TextView tvEndtime;
    private Context mContext = this;


    @Override
    public int getLayoutId() {
        return R.layout.activity_carverify_info;
    }

    @Override
    public void initView() {
        titleName.setText("认证信息");
        getUserCarInfo();
    }

    @OnClick({R.id.title_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.title_back:
                AppManager.getAppManager().finishActivity();
                break;
        }
    }

    //认证信息
    private void getUserCarInfo() {
        ApiStore.getInstance().getApiService(UrlConstant.Request.BASE_URL).getUserCarInfo(((MyApplication) getApplication()).getRequestFieldMap()).enqueue(new Callback<UserCarInforBean>() {
            @Override
            public void onResponse(Call<UserCarInforBean> call, Response<UserCarInforBean> response) {
                if (response.isSuccessful() && response.body() != null) {
                    if (response.body().getStatus() == 200) {
                        UserCarInforBean carInforBean = response.body();
                        tvName.setText(carInforBean.getAttachment().getName());
                        tvCartype.setText(carInforBean.getAttachment().getQuasiDrivingType());
                        tvStarttime.setText(carInforBean.getAttachment().getLicensingOfTime());
                        tvEndtime.setText(carInforBean.getAttachment().getDrivingLicencePeriodOfValidity());
                    } else {
                        ToastCompat.makeText(mContext, response.body().getMessage(), Toast.LENGTH_SHORT).show();
                    }
                } else {
                    ToastCompat.makeText(mContext, getResources().getString(R.string.serverError), Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onFailure(Call<UserCarInforBean> call, Throwable t) {
                ToastCompat.makeText(mContext, getResources().getString(R.string.badNetwork), Toast.LENGTH_SHORT).show();
                Log.i("neterror", "011" + t);
            }
        });

    }

    @Override
    public void onBackPressed() {
        AppManager.getAppManager().finishActivity();
    }
}
